/*
 * HTTPRequest.h
 *      Author: DePhille
 */

#ifndef HTTPREQUEST_H_
#define HTTPREQUEST_H_

#include "NetClient.h"


// HTTPRequest object:
struct PC_HTTPRequest{
	gchar*					destination;				// The destination for the request.
	gchar*					userAgent;					// User-agent to put in HTTP header.
	gboolean				useHTTP11;					// Whether HTTP1.1 or HTTP1.0 should be used.
	gchar*					payload;					// The payload of the HTTP request
	unsigned short			method;						// The method of the request (GET, POST, ...). See PC_HTTPREQUEST_*.
	gchar*					uri;						// The URI for the request. (Relative to the destination)
	gchar*					contentType;				// The content-type of the payload.
	GList*					customHeaders;				// Any custom HTTP headers to add. (Make sure not to overwrite the required ones)
	gchar*					token;						// The authorization token to use.
	PC_Net_HTTP_CallBack	callBack;					// A function which will be called when a response is received.
	gpointer				callBackData;				// Any custom data which will be passed to the callBack.
	unsigned short			timeOut;					// Time in seconds after which the request should time out.
	time_t					timeSent;					// UNIX timestamp on which this request was sent.
	unsigned short			maxRetries;					// Maximum number of retries after the request has failed.
	unsigned short			retries;					// The amount of retries that were needed in order for the request to succeed.
	PurpleUtilFetchUrlData*	urlData;					// Links the Request with a PurpleRequest.
};



// Methods:
#define PC_HTTPREQUEST_GET			0
#define PC_HTTPREQUEST_POST			1

// Default settings:
#define PC_HTTPREQUEST_CONTENTTYPE	"text/plain"
#define	PC_HTTPREQUEST_MAXRETRIES	2
#define	PC_HTTPREQUEST_TIMEOUT		10



// Methods:
static PC_HTTPRequest*	 	PC_HTTPRequest_New();
static void 				PC_HTTPRequest_Delete(PC_HTTPRequest* request);
static void 				PC_HTTPRequest_delCustomHeader(PC_HTTPRequest* request, const gchar* headerName);
static void 				PC_HTTPRequest_addCustomHeader(PC_HTTPRequest* request, const gchar* headerName, const gchar* headerValue);
static void					PC_HTTPRequest_SetCallBack(PC_HTTPRequest* request, PC_Net_HTTP_CallBack callBack, gpointer callBackData);
static gchar*				PC_HTTPRequest_ToString(const PC_HTTPRequest* request);
static void					PC_HTTPRequest_SetMaxRetries(PC_HTTPRequest* request, unsigned short maxRetries);
static void					PC_HTTPRequest_SetTimeOut(PC_HTTPRequest* request, unsigned short timeOut);

#endif /* HTTPREQUEST_H_ */
